//
// Created by 王乐 on 2022/2/22.
//

#include "LePhyQuadSpawnerBehaviour.h"

#include "LeScene.h"
#include "LePhysicsQuadGameObject.h"

#include "LeTime.h"
#include "LeInput.h"

#include "LeUtils.h"

LePhyQuadSpawnerBehaviour::LePhyQuadSpawnerBehaviour()
{}

LePhyQuadSpawnerBehaviour::~LePhyQuadSpawnerBehaviour()
{

}

void LePhyQuadSpawnerBehaviour::Start()
{
    m_IntervelTime = 0.15;
    m_CurTime = 0;
}

void LePhyQuadSpawnerBehaviour::Update()
{
    if(LeInput::getKey(GLFW_KEY_SPACE) == GLFW_PRESS)
    {
        m_CurTime += LeTime::dDeltaTime;
        if(m_CurTime > m_IntervelTime)
        {
            m_CurTime = 0;

            float xrange = LeMath::getRandomF(-0.1, 0.1);
            LePhysicsQuadGameObject* pNewObj = new LePhysicsQuadGameObject();
            pNewObj->setParameter(m_pTransform->m_Position + glm::vec3(xrange, 1.0, 0), glm::vec3(0,0,0), glm::vec3(0.1,0.1,0.1),
                                  "/Users/wangle/CLionProjects/Leste/res/cubicbox.png");
            LeScene::getInstance()->addGameObject(pNewObj);
        }
    }
}
